package num190;

/**
 * 190. 颠倒二进制位
 * 题目：https://leetcode-cn.com/problems/reverse-bits/
 * 三叶姐题解: https://leetcode-cn.com/problems/reverse-bits/solution/yi-ti-san-jie-dui-cheng-wei-zhu-wei-fen-ub1hi/
 * 三叶姐
 *
 * 「对称位」构造
 */
public class Solution {
    public int reverseBits(int n) {
        int ans = 0;
        for (int i = 0; i < 32; i++) {
            int t = (n >> i) & 1;
            if (t == 1) {
                ans |= (1 << (31 - i));
            }
        }
        return ans;
    }
}
